Access the Word Object from word.dxl

Hi there,

i'm using DOORS 9.2 and want to add/change Word document properties after the word export has been done.

I have automated the export like shown in this forum by overriding some UI functions of word.dxl.
 

DB theDiag = null
 
// Now override block and show, to only do realize
void show  (DB x) { realize x; theDiag = x }
void block (DB x) { realize x; theDiag = x }
 
if (null current Module) {
    print "You need to have a current Module set for the export."
        halt
}
 
// now include the word.dxl -> this will pop up the dialog, but not halt execution
// due to the overrides above
#include <standard/export/office/word.dxl>
 
// here we can change the dialog options. See itfui2.inc and word.dxl for all 
// the options
set(exportHeadingsToggle, false)   // turn off export of headings
 
string Template_Path = (getenv("Home")) "\\lib\\word\\my_template.dot"
 
set(advancedNormalTemplateToggle, false) 
set(advancedTemplateName, Template_Path)
 
// now manually launch the export button callback
doExport theDiag
 
// add/modify document properties
// See: http://www.ibm.com/developerworks/wikis/x/iwCPBQ
 
checkRes(oleGet (objWord, cPropertyActiveDocument, objDoc))
checkRes(oleGet (objDoc, cPropertyCustomDocumentProperties, objCustomProperties))

 


However, the first "oleGet" fails with "null OleAutoObj parameter was passed into argument position 1".

So, how do i get hold of the word document instance that has been created by "doExport"?

Regards,
Peter

 


peter_schaefer - Thu Mar 22 06:43:22 EDT 2012

Re: Access the Word Object from word.dxl
llandale - Thu Mar 22 12:33:37 EDT 2012

doExport() calls userExportCode() which calls wordDoExportVBA() which deletes and erases objWord (and others) at its end via closeIfNonNull().

Seems to me you need to re-establish the link to MS-Word, first simply try to "createWordApplication()" again; but you may also need this:

  • checkRes(oleGet(objWord,cPropertyOptions,objOpt))

-Louie

Re: Access the Word Object from word.dxl
peter_schaefer - Fri Mar 23 08:14:07 EDT 2012

llandale - Thu Mar 22 12:33:37 EDT 2012
doExport() calls userExportCode() which calls wordDoExportVBA() which deletes and erases objWord (and others) at its end via closeIfNonNull().

Seems to me you need to re-establish the link to MS-Word, first simply try to "createWordApplication()" again; but you may also need this:

  • checkRes(oleGet(objWord,cPropertyOptions,objOpt))

-Louie

Thanks Louie, that put me on the right track.

It works like shown below:

// Need OLE argument block
objArgBlock = create
// (Re-)attach to existing word application
objWord = oleGetAutoObject(cObjWordApplication)
// Get Active Document
checkRes(oleGet (objWord, cPropertyActiveDocument, objDoc))
// Get CustomProperties Collection
checkRes(oleGet (objDoc, cPropertyCustomDocumentProperties, objCustomProperties))
 
int nPropCount
int nPropNumber
string strName
 
oleGet(objCustomProperties, "Count", nPropCount)
for (nPropNumber = 1; nPropNumber <= nPropCount; nPropNumber++) {
    clear objArgBlock
    put(objArgBlock, nPropNumber)
    oleGet(objCustomProperties, cMethodItem, objArgBlock, objProperty)
    checkRes(oleGet(objProperty, "Name", strName))
    print "Property " nPropCount " is called " strName
}

 


Best regards,
Peter